#include<iostream>

#include"sorted_array.h"

using namespace std;

typedef float* FloatPtr;

int main()
{

  int arraySize = 5;
  FloatPtr array = new float[arraySize];
  int size_used = 0;
  float user_values;

  cout << "Enter next value to insert: ";
  
  while(cin >> user_values){
    
    array_insert(array, size_used, user_values);
    
    array_print(cout, array, size_used);
    
    if(size_used == arraySize){
      cout << "Array size increased." << endl;

      arraySize += 5;
      FloatPtr temp = new float[arraySize];
      int temp_size_used = 0;
      array_copy(temp, array, temp_size_used, size_used);

      delete [] array;
      array = temp;
      array_print(cout, array, size_used);
      
      //delete [] temp;
    }
    cin.clear();
    cout << "Enter next value to insert: ";
  }
  
  cout << "\nArray after all insertions: " << endl;
  array_print(cout, array, size_used);
  
  cin.clear();

  FloatPtr copy = new float[arraySize];
  int copy_size_used = 0;
  array_copy(copy, array, copy_size_used, size_used);
  
  cout << "Enter next value to remove: ";
  
  while(cin >> user_values){
    
    if(array_find(array, size_used, user_values) < 0)
      {
	cout << "No such value." << endl;
	array_print(cout, array, size_used);
	cin.clear();
	cout << "Enter next value to remove: ";
	continue;
      }
    else
      {
	array_remove(array, size_used, array_find(array, size_used, user_values));
	array_print(cout, array, size_used);
	
	if(size_used == 0){
	  break;
	}
      }
    
    cin.clear();
    cout << "Enter next value to insert: ";
  }  
  
  cin.clear();
    
  if(array_find(array, size_used, user_values) == 0)
    cout << "\nArray empty." << endl;
  
  cout << "Array after all removals: " << endl;
  array_print(cout, array, size_used);
  
  cout << "Copy before all removals:" << endl;
  array_print(cout, copy, copy_size_used);
  cout << endl;

  delete [] array;
  delete [] copy;

}
